package com.inspiration.config;

import cn.hutool.core.util.StrUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author : Vincent.jiao
 * @Date : 2023/11/4 19:15
 * @Version : 1.0
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object user = session.getAttribute("user");
        if(user != null && StrUtil.equals(user.toString(), "true")){
            return true;
        }

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().print("<script>window.history.go(-1);</script>");
        return false;
    }
}
